package com.huawei.hms.support.api.push.b.a;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.webkit.URLUtil;
import com.huawei.fastengine.fastview.NavigationUtils;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;
import com.huawei.hms.support.log.HMSLog;
import com.huawei.hms.utils.ResourceLoaderUtil;
import com.huawei.hms.utils.Util;
import java.util.ArrayList;
import java.util.List;

public class a {
    private static final String[] a = new String[]{"phone", "url", "app", "cosa", "rp"};
    private Context b;
    private com.huawei.hms.support.api.push.b.b.a c;

    public a(Context context, com.huawei.hms.support.api.push.b.b.a aVar) {
        this.b = context;
        this.c = aVar;
    }

    public static boolean a(String str) {
        for (String equals : a) {
            if (equals.equals(str)) {
                return true;
            }
        }
        return false;
    }

    public void a() {
        HMSLog.d("PushSelfShowLog", "enter launchNotify()");
        if (this.b == null || this.c == null) {
            HMSLog.d("PushSelfShowLog", "launchNotify  context or msg is null");
        } else if ("app".equals(this.c.j())) {
            c();
        } else if ("cosa".equals(this.c.j())) {
            f();
        } else if ("phone".equals(this.c.j())) {
            b();
        } else if ("rp".equals(this.c.j())) {
            HMSLog.w("PushSelfShowLog", this.c.j() + " not support rich message.");
        } else if ("url".equals(this.c.j())) {
            HMSLog.w("PushSelfShowLog", this.c.j() + " not support URL.");
        } else {
            HMSLog.d("PushSelfShowLog", this.c.j() + " is not exist in hShowType");
        }
    }

    private void b() {
        HMSLog.d("PushSelfShowLog", "enter launchCall");
        try {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.DIAL").setData(Uri.parse(NavigationUtils.TEL_SCHEMA_PREF + this.c.n())).setFlags(268435456);
            this.b.startActivity(intent);
        } catch (Throwable e) {
            HMSLog.e("PushSelfShowLog", e.toString(), e);
        }
    }

    private void c() {
        try {
            HMSLog.i("PushSelfShowLog", "enter launchApp, appPackageName =" + this.c.o() + ",and msg.intentUri is " + this.c.g());
            if (com.huawei.hms.support.api.push.b.d.a.c(this.b, this.c.o())) {
                f();
                return;
            }
            HMSLog.i("PushSelfShowLog", "enter launch app, appPackageName =" + this.c.o() + ",and msg.intentUri is " + this.c.g());
            d();
        } catch (Exception e) {
            HMSLog.e("PushSelfShowLog", "launchApp error:" + e.toString());
        }
    }

    private String b(String str) {
        try {
            int indexOf = str.indexOf(63);
            if (indexOf == -1) {
                return str;
            }
            int i;
            String[] split = str.substring(indexOf + 1).split(ContainerUtils.FIELD_DELIMITER);
            List arrayList = new ArrayList();
            for (String str2 : split) {
                if (!(str2.startsWith("h_w_hiapp_referrer") || str2.startsWith("h_w_gp_referrer"))) {
                    arrayList.add(str2);
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            int size = arrayList.size();
            for (i = 0; i < size; i++) {
                stringBuilder.append((String) arrayList.get(i));
                if (i < arrayList.size() - 1) {
                    stringBuilder.append(ContainerUtils.FIELD_DELIMITER);
                }
            }
            String str3 = "";
            if (arrayList.size() == 0) {
                str3 = str.substring(0, indexOf);
            } else {
                str3 = str.substring(0, indexOf + 1) + stringBuilder.toString();
            }
            HMSLog.d("PushSelfShowLog", "after delete referrer, the new IntentUri is:" + str3);
            return str3;
        } catch (Exception e) {
            HMSLog.e("PushSelfShowLog", "delete referrer exception" + e.toString());
            return str;
        }
    }

    private void d() {
        try {
            StringBuilder stringBuilder = new StringBuilder();
            if (!TextUtils.isEmpty(this.c.g())) {
                stringBuilder.append("&referrer=").append(Uri.encode(b(this.c.g())));
            }
            String str = "market://details?id=" + this.c.o() + stringBuilder;
            Intent intent = new Intent(ACTION.HWID_SCHEME_URL);
            intent.setData(Uri.parse(str));
            intent.setPackage("com.huawei.appmarket");
            Intent intent2 = new Intent(ACTION.HWID_SCHEME_URL);
            intent2.setData(Uri.parse(str));
            intent2.setPackage("com.android.vending");
            if (com.huawei.hms.support.api.push.b.d.a.a(this.b, "com.android.vending", intent2).booleanValue()) {
                intent2.setFlags(402653184);
                HMSLog.i("PushSelfShowLog", "open google play store's app detail, IntentUrl is:" + intent2.toURI());
                this.b.startActivity(intent2);
            } else if (com.huawei.hms.support.api.push.b.d.a.a(this.b, "com.huawei.appmarket", intent).booleanValue()) {
                intent.setFlags(402653184);
                HMSLog.i("PushSelfShowLog", "open HiApp's app detail, IntentUrl is:" + intent.toURI());
                this.b.startActivity(intent);
            } else {
                HMSLog.i("PushSelfShowLog", "open app detail by browser.");
                e();
            }
        } catch (Exception e) {
            HMSLog.e("PushSelfShowLog", "open market app detail failed,exception:" + e);
        }
    }

    private void e() {
        String queryParameter;
        Exception e;
        String str = "";
        String str2 = "";
        try {
            Uri parse = Uri.parse(Uri.decode(this.c.g()));
            try {
                queryParameter = parse.getQueryParameter("h_w_hiapp_referrer");
            } catch (Exception e2) {
                HMSLog.i("PushSelfShowLog", "parse h_w_hiapp_referrer faied");
                queryParameter = str;
            }
            try {
                str2 = parse.getQueryParameter("h_w_gp_referrer");
            } catch (Exception e3) {
                try {
                    HMSLog.i("PushSelfShowLog", "parse h_w_hiapp_referrer faied");
                } catch (Exception e4) {
                    e = e4;
                    HMSLog.w("PushSelfShowLog", "parse intentUri error" + e.toString());
                    if (Util.isEMUI()) {
                    }
                    HMSLog.i("PushSelfShowLog", "not EMUI system or not in China, open google play web, referrer: " + str2);
                    str2 = Uri.decode(str2);
                    if (!URLUtil.isValidUrl(str2)) {
                        ResourceLoaderUtil.setmContext(this.b);
                        str2 = ResourceLoaderUtil.getString("hms_push_google") + this.c.o();
                    }
                    HMSLog.i("PushSelfShowLog", "open the URL by browser: " + str2);
                    com.huawei.hms.support.api.push.b.d.a.d(this.b, str2);
                }
            }
        } catch (Exception e5) {
            Exception exception = e5;
            queryParameter = str;
            e = exception;
            HMSLog.w("PushSelfShowLog", "parse intentUri error" + e.toString());
            if (Util.isEMUI()) {
            }
            HMSLog.i("PushSelfShowLog", "not EMUI system or not in China, open google play web, referrer: " + str2);
            str2 = Uri.decode(str2);
            if (URLUtil.isValidUrl(str2)) {
                ResourceLoaderUtil.setmContext(this.b);
                str2 = ResourceLoaderUtil.getString("hms_push_google") + this.c.o();
            }
            HMSLog.i("PushSelfShowLog", "open the URL by browser: " + str2);
            com.huawei.hms.support.api.push.b.d.a.d(this.b, str2);
        }
        if (Util.isEMUI() || !Util.isChinaROM()) {
            HMSLog.i("PushSelfShowLog", "not EMUI system or not in China, open google play web, referrer: " + str2);
            str2 = Uri.decode(str2);
            if (URLUtil.isValidUrl(str2)) {
                ResourceLoaderUtil.setmContext(this.b);
                str2 = ResourceLoaderUtil.getString("hms_push_google") + this.c.o();
            }
        } else {
            HMSLog.i("PushSelfShowLog", "It is China device, open Huawei market web, referrer: " + queryParameter);
            str2 = Uri.decode(queryParameter);
            if (!URLUtil.isValidUrl(str2)) {
                if (this.b != null) {
                    ResourceLoaderUtil.setmContext(this.b);
                    str2 = ResourceLoaderUtil.getString("hms_push_vmall");
                } else {
                    str2 = null;
                }
            }
        }
        HMSLog.i("PushSelfShowLog", "open the URL by browser: " + str2);
        com.huawei.hms.support.api.push.b.d.a.d(this.b, str2);
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void f() {
        /*
        r6 = this;
        r0 = 0;
        r1 = "PushSelfShowLog";
        r2 = "run into launchCosaApp ";
        com.huawei.hms.support.log.HMSLog.i(r1, r2);
        r1 = "PushSelfShowLog";
        r2 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x00dc }
        r2.<init>();	 Catch:{ Exception -> 0x00dc }
        r3 = "enter launchExistApp cosa, appPackageName =";
        r2 = r2.append(r3);	 Catch:{ Exception -> 0x00dc }
        r3 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r3 = r3.o();	 Catch:{ Exception -> 0x00dc }
        r2 = r2.append(r3);	 Catch:{ Exception -> 0x00dc }
        r3 = ",and msg.intentUri is ";
        r2 = r2.append(r3);	 Catch:{ Exception -> 0x00dc }
        r3 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r3 = r3.g();	 Catch:{ Exception -> 0x00dc }
        r2 = r2.append(r3);	 Catch:{ Exception -> 0x00dc }
        r2 = r2.toString();	 Catch:{ Exception -> 0x00dc }
        com.huawei.hms.support.log.HMSLog.i(r1, r2);	 Catch:{ Exception -> 0x00dc }
        r1 = r6.b;	 Catch:{ Exception -> 0x00dc }
        r2 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r2 = r2.o();	 Catch:{ Exception -> 0x00dc }
        r2 = com.huawei.hms.support.api.push.b.d.a.b(r1, r2);	 Catch:{ Exception -> 0x00dc }
        r1 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r1 = r1.g();	 Catch:{ Exception -> 0x00dc }
        if (r1 == 0) goto L_0x00ad;
    L_0x004a:
        r1 = r6.c;	 Catch:{ Exception -> 0x008e }
        r1 = r1.g();	 Catch:{ Exception -> 0x008e }
        r3 = 0;
        r1 = android.content.Intent.parseUri(r1, r3);	 Catch:{ Exception -> 0x008e }
        r3 = "PushSelfShowLog";
        r4 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x008e }
        r4.<init>();	 Catch:{ Exception -> 0x008e }
        r5 = "Intent.parseUri(msg.intentUri, 0),";
        r4 = r4.append(r5);	 Catch:{ Exception -> 0x008e }
        r5 = r1.toURI();	 Catch:{ Exception -> 0x008e }
        r4 = r4.append(r5);	 Catch:{ Exception -> 0x008e }
        r4 = r4.toString();	 Catch:{ Exception -> 0x008e }
        com.huawei.hms.support.log.HMSLog.i(r3, r4);	 Catch:{ Exception -> 0x008e }
        r3 = r6.b;	 Catch:{ Exception -> 0x008e }
        r4 = r6.c;	 Catch:{ Exception -> 0x008e }
        r4 = r4.o();	 Catch:{ Exception -> 0x008e }
        r3 = com.huawei.hms.support.api.push.b.d.a.a(r3, r4, r1);	 Catch:{ Exception -> 0x008e }
        r3 = r3.booleanValue();	 Catch:{ Exception -> 0x008e }
        if (r3 == 0) goto L_0x013c;
    L_0x0083:
        r0 = 1;
    L_0x0084:
        if (r1 != 0) goto L_0x00fa;
    L_0x0086:
        r0 = "PushSelfShowLog";
        r1 = "launchCosaApp,intent == null";
        com.huawei.hms.support.log.HMSLog.i(r0, r1);	 Catch:{ Exception -> 0x00dc }
    L_0x008d:
        return;
    L_0x008e:
        r1 = move-exception;
        r3 = "PushSelfShowLog";
        r4 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x00dc }
        r4.<init>();	 Catch:{ Exception -> 0x00dc }
        r5 = "intentUri error";
        r4 = r4.append(r5);	 Catch:{ Exception -> 0x00dc }
        r1 = r1.toString();	 Catch:{ Exception -> 0x00dc }
        r1 = r4.append(r1);	 Catch:{ Exception -> 0x00dc }
        r1 = r1.toString();	 Catch:{ Exception -> 0x00dc }
        com.huawei.hms.support.log.HMSLog.w(r3, r1);	 Catch:{ Exception -> 0x00dc }
        r1 = r2;
        goto L_0x0084;
    L_0x00ad:
        r1 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r1 = r1.p();	 Catch:{ Exception -> 0x00dc }
        if (r1 == 0) goto L_0x013a;
    L_0x00b5:
        r1 = new android.content.Intent;	 Catch:{ Exception -> 0x00dc }
        r3 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r3 = r3.p();	 Catch:{ Exception -> 0x00dc }
        r1.<init>(r3);	 Catch:{ Exception -> 0x00dc }
        r3 = r6.b;	 Catch:{ Exception -> 0x00dc }
        r4 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r4 = r4.o();	 Catch:{ Exception -> 0x00dc }
        r3 = com.huawei.hms.support.api.push.b.d.a.a(r3, r4, r1);	 Catch:{ Exception -> 0x00dc }
        r3 = r3.booleanValue();	 Catch:{ Exception -> 0x00dc }
        if (r3 == 0) goto L_0x013a;
    L_0x00d2:
        r2 = r6.c;	 Catch:{ Exception -> 0x00dc }
        r2 = r2.o();	 Catch:{ Exception -> 0x00dc }
        r1.setPackage(r2);	 Catch:{ Exception -> 0x00dc }
        goto L_0x0084;
    L_0x00dc:
        r0 = move-exception;
        r1 = "PushSelfShowLog";
        r2 = new java.lang.StringBuilder;
        r2.<init>();
        r3 = "launch Cosa App exception";
        r2 = r2.append(r3);
        r0 = r0.toString();
        r0 = r2.append(r0);
        r0 = r0.toString();
        com.huawei.hms.support.log.HMSLog.e(r1, r0);
        goto L_0x008d;
    L_0x00fa:
        r2 = r6.b;	 Catch:{ Exception -> 0x00dc }
        r2 = com.huawei.hms.support.api.push.b.d.a.a(r2, r1);	 Catch:{ Exception -> 0x00dc }
        if (r2 != 0) goto L_0x010a;
    L_0x0102:
        r0 = "PushSelfShowLog";
        r1 = "no permission to start Activity";
        com.huawei.hms.support.log.HMSLog.w(r0, r1);	 Catch:{ Exception -> 0x00dc }
        goto L_0x008d;
    L_0x010a:
        if (r0 == 0) goto L_0x0134;
    L_0x010c:
        r0 = 268435456; // 0x10000000 float:2.5243549E-29 double:1.32624737E-315;
        r1.addFlags(r0);	 Catch:{ Exception -> 0x00dc }
    L_0x0111:
        r0 = "PushSelfShowLog";
        r2 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x00dc }
        r2.<init>();	 Catch:{ Exception -> 0x00dc }
        r3 = "start ";
        r2 = r2.append(r3);	 Catch:{ Exception -> 0x00dc }
        r3 = r1.toURI();	 Catch:{ Exception -> 0x00dc }
        r2 = r2.append(r3);	 Catch:{ Exception -> 0x00dc }
        r2 = r2.toString();	 Catch:{ Exception -> 0x00dc }
        com.huawei.hms.support.log.HMSLog.i(r0, r2);	 Catch:{ Exception -> 0x00dc }
        r0 = r6.b;	 Catch:{ Exception -> 0x00dc }
        r0.startActivity(r1);	 Catch:{ Exception -> 0x00dc }
        goto L_0x008d;
    L_0x0134:
        r0 = 805437440; // 0x30020000 float:4.7293724E-10 double:3.97938969E-315;
        r1.setFlags(r0);	 Catch:{ Exception -> 0x00dc }
        goto L_0x0111;
    L_0x013a:
        r1 = r2;
        goto L_0x00d2;
    L_0x013c:
        r1 = r2;
        goto L_0x0084;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hms.support.api.push.b.a.a.f():void");
    }
}
